<?php
final class PagesController extends ABController{
	/**
	 * This implement autoload models
	 **/
	public $a_models = array('post', 'tag', 'link');

	function index(){
		switch($this->a_conf['index']){
			case 0:
				$this->redirect('pages', 'all');
			break;
		}
	}

	function view($s_idpost){
		$o_dbpost = new Post();
		$o_post = $o_dbpost->getPost($s_idpost);
		if($o_post){
			$this->post = $o_post;
			$this->ptitle = $o_post->title;
			$this->canonical = ABapi::encodeURL($o_post->title);
			if($o_post->allowc){
				$o_Captcha = new ABCaptcha();
				session_id(md5($_SERVER['REMOTE_ADDR']));
				session_name('comments');
				session_start();
				$_SESSION['c'] = serialize($o_Captcha);
				$_SESSION['referer'] = $_SERVER['REQUEST_URI'];
				$this->comments = $o_dbpost->getComments($o_post->id_post);
				$this->fcaptcha = $o_Captcha->getAsker();
			}
			$this->render(false, '', $this->a_conf['style']);
		}
	}

	function all(){
		$o_dbpost = new Post();
		$this->ptitle='Escritos recientemente';
		$this->posts = $o_dbpost->getPosts();
		$this->render(false, 'listpost', $this->a_conf['style']);
	}

	function tag($s_tag){
		$o_dbtag = new Tag();
		$a_post = $o_dbtag->getPosts($s_tag);
		if (empty($a_post)){header('HTTP/1.0 404 Not Found');}
		$this->posts = $a_post;
		$this->ptitle= strip_tags($s_tag);
		$this->render(false, 'listpost', $this->a_conf['style']);
	}

	function search($s_query){
		$s_query = filter_var($s_squery, FILTER_SANITIZE_STRING);
	}

	protected function finalize(){
		$a_conf = $this->a_conf;
		$o_dbtag = new Tag();
		$o_dblink = new Link();
		$this->title = $a_conf['title'];
		$this->desc  = $a_conf['desc'];
		$this->style = $a_conf['style'];
		$this->link  = $o_dblink->toindex();
		$this->category  = $o_dbtag->getTags();
	}
}
?>
